2.1 Overview

SLiM was built primarily with MacOS in mind, and so no native Windows version exists. However, since MacOS is very similar to many Linux distributions, we can use Windows 10’s new Windows subsystem for Linux to run SLiM on Windows (or if we want to be pedantic, we’re running SLiM on a Linux kernel running off Windows). The SLiM manual (SOURCE) has a pretty good step-by-step instruction for this if you want to run SLiM by itself, and not worry about using WSL for anything else. However, Linux is a fantastic base for many scientific applications, such as connecting to supercomputers, which are more often than not Linux-based. As such, I’ll be guiding you through installing a desktop environment for WSL, installing R, Rstudio, and SLiM, and getting you up to speed with some basics of using Linux. For MacOS users, you can simply install SLiM using the installer package available here. There are also instructions in the SLiM manual for building SLiM from source for MacOS if you would prefer that. For Windows users not on Windows 10, I’m afraid there is no way at the moment to run SLiM “natively” on Windows - your best bet would be to dual boot a Linux distribution, or run a virtual machine with VirtualBox or VMware.

Box 2.1.1

Linux (or any Unix based operating system, such as MacOS) differs from Windows in the sense that absolutely everything is treated as a file - including devices like printers or monitors. These devices have specialised files that store information about that device. Programs can read those files (or write to them) to communicate with the device itself. Note that these aren’t files in the sense that they are a .txt or something, but they are exposed to the filesystem and can be treated as different files depending on what commands you give it.

For example, you could enter

cat /proc/cpuinfo

or

gedit /proc/cpuinfo

to print your CPU information to the terminal, or open the file with a text editor so it is readable.

You can also use various ‘files’ such as /dev/null or /dev/urandom to instruct other commands. Redirecting output from a command to /dev/null will silence the output so it isn’t displayed in the terminal:

slim ~/PolygenicSLiM/box2.1.slim # With output
## // Initial random seed:
## 1641698792951
## 
## // RunInitializeCallbacks():
## initializeMutationRate(1e-07);
## initializeMutationType(1, 0.5, "f", 0);
## initializeGenomicElementType(1, m1, 1);
## initializeGenomicElement(g1, 0, 999);
## initializeRecombinationRate(1e-08);
## 
## // Starting run at generation <start>:
## 1 
## 
## Look at this messy output!
slim ~/PolygenicSLiM/box2.1.slim > /dev/null # Output nullified

/dev/urandom will generate pseudorandom numbers:

od -d /dev/urandom | head # Generate random decimal integers
## 0000000 41218 16309 31869 36079 25844 45136 60848 63101
## 0000020 50309 39493 20371 61264 55410 57803 33718 56530
## 0000040 27853  4030 22459 37211 19730  9746 10444  7375
## 0000060  3055 53463 54721 32909 19952 33830 20980   188
## 0000100 30617 34640 32613 61100 26556 26560 33121 65181
## 0000120  3975 51360 51477 39266  5227 52465 46909  8663
## 0000140 23151  7918 29455  3254 27620 36876 16464 30269
## 0000160 42713 49729 58221 31746 46990 13657 48552 21525
## 0000200 25591 49592  7098 20821 33970 50583 57198 13567
## 0000220 23443 50661 19031 25457  9622 25143 42544 42675

The power of having these very specific commands which can act on a lot of different types of files is that Linux users can chain together these commands to efficiently solve a larger problem.

2.2 Why Linux?

To many people, the term ‘Linux user’ is analogous to ‘computer wizard’ or ‘weirdo’. Unfortunately for you, future weirdo, Linux is an incredibly helpful tool for scientific applications. I’ve already mentioned that SLiM doesn’t run on Windows natively, but that is far from the only scientific program that requires (or runs better on ) a Linux operating system. Although user-friendly, both Windows and MacOS are extremely bloated, meaning that just running the operating system requires a massive amount of memory and CPU resources that your other applications cannot use. Linux is a barebones system, with the idea being that the user can build the operating system how they want by installing only the features that they will use, saving memory and processor power for the task/s at hand. Another reason for Linux’s speed and low memory footprint is its way of storing files (as mentioned in Box 2.1.1), which is very different to Windows. It takes a bit of getting used to, but in the end you will save massive amounts of time using Linux versus Windows or MacOS (but especially Windows). However, there are still programs that you might need to run in Windows. Sometimes specialised software is only built for one operating system, being Windows or Linux/MacOS. There are three options here: dual-boot by installing a Windows and Linux operating system on separate hard drives (or partitions on one hard drive), use a traditional virtual machine such as VMware or VirtualBox, or use the Windows 10 Subsystem for Linux (WSL). Dual-booting is great if you rarely use one of your installed operating systems, but generally a bit of a pain if you’re constantly wanting to switch between using Windows and Linux software (you can only run one OS at a time, so you need to reboot if you want to use software in the other OS). VMware and VirtualBox are very resource-intensive, which negates the speed advantage you get from running Linux over Windows. WSL, however, is much faster.

2.3 The Windows Subsystem for Linux

Windows 10 introduced a new way to emulate a Linux machine via a Windows operating system. Through illegal* computer trickery, Microsoft managed to show everyone (through a feature in their own operating system) that a Linux machine running on a Windows machine is faster than a Windows machine by itself. The advantage of this approach is accessing your data between operating systems is very easy: your Windows files are visible in Linux, and you can save files to your Windows machine directly using Linux programs. This way, you can use Linux commands such as sed and grep to filter output (extremely quickly) and directly save the output to files that Windows programs can read! Hence, we can run SLiM simulations, storing the output wherever you want, and then use Windows to do data analysis (although you could do that analysis in Linux also). Below, I’ll provide some instructions for installing WSL 2, a Linux distribution (Ubuntu 20.04), and some basics for getting started with Ubuntu.

*: Probably not actually illegal, but I’m not a lawyer.

2.2 Installing WSL

There are two choices for running WSL: WSL 1 or WSL 2. Both are fairly similar in speed, however WSL 2 uses a real Linux kernel and an extremely fast virtual machine (along with a virtual hard drive), whereas WSL 1 used a translation layer (instead of a native kernel) to translate between windows and a linux distribution. Ultimately , the main difference is WSL 2 is slightly slower when it comes to copying files between Windows and Linux, but faster nearly everywhere else. Although both versions run SLiM fine*, I’ll be opting for WSL 2.

*One bug I did find with WSL 1 was that Windows Security seems to treat a few programs running on Linux as something suspicious. The result is that Windows Security uses 50% or more CPU while those programs are running. SLiM is included in this, so if for whatever reason you use WSL 2, remember to turn off real-time protection during your SLiM runs and then remember to turn it back on when the run is finished.

To install WSL, you’ll need to be on Windows 10 version 1903 (build 18362) or newer. To check your version number, run winver.exe. This will tell you the version and build number (build number being in brackets).

Instructions for installing WSL 2 can be found on the Microsoft website here. You’ll want to install Ubuntu 20.04 LTS, which can be found on the Microsoft Store (for free).

This will install your Linux distribution to the C:/ drive by defualt. If you have limited space on C:/ you can move it to an alternative drive, using this tool. I recommend installing git bash on Windows and running it that way. A side effect of moving your Linux installation is the default user is replaced by root (basically admin for Linux) for some reason, but this is easy enough to fix. In your Ubuntu terminal, open up /etc/wsl.conf with nano and add the following to the end of the file:

# Open wsl.conf with the nano text editor, using administrator permissions
sudo nano /etc/wsl.conf

# Add the following lines to the bottom of wsl.conf

[user]
default=YOUR_USERNAME

If wsl.conf doesn’t exist, create the file manually with sudo touch /etc/wsl.conf. After you’ve added that line, close Ubuntu, then in PowerShell run:

wsl -terminate Ubuntu

When you next open Ubuntu, you should login as your user again. If that doesn’t work, open up PowerShell and enter:

ubuntu config --default-user YOUR_USERNAME

Congratulations! You now have a working version of Ubuntu 20.04 LTS running via Windows 10.

2.3 Installing a desktop and setting up X11

At this point you have a Ubuntu terminal which you can use to input commands. This is perfectly usable (even with a desktop you’ll be using the terminal quite a bit), but you’ll probably want a desktop environment to be more comfortable. To do this, enter the following:

sudo apt-get update # Refresh Ubuntu's list of software updates
sudo apt-get upgrade # Download and install package updates
sudo apt install ubuntu-desktop gnome

Box 2.3.1

While we’ll be installing Gnome for this installation, there are a number of other desktop environments you may want to have a look at. Below are a list of some, with their pros and cons.

The first two commands will update your base installation and packages; the third will install GNOME (a Linux desktop environment) and relevant dependencies.

While those files are downloading, you’ll need to grab a X11 program for Windows. X11 is how Linux draws graphics, so we need that so that when you run GNOME, Linux has a window to draw your desktop. I recommend VcXsrv, which is easily configurable.

After downloading and installing VcXsrv and GNOME, there’s a little workaround to get it working on WSL. In the Ubuntu terminal enter the following:

sudo nano ~/.bashrc # Open up .bashrc in the nano text editor

# .bashrc contains commands that run on startup
# Add this one to the bottom of the file in nano and press ctrl+o to save and ctrl+x to exit

export LIBGL_ALWAYS_INDIRECT=0

This has something to do with how Linux handles OpenGL graphics drivers, but that’s about as much depth into it as I can go. Without doing this, SLiMgui doesn’t render properly. Next, there’s a setting that needs to be enabled which defaults to disabled in WSL. In WSL 1, this broke a lot of programs (particularly compilers), but it seems to work fine in WSL2. In Terminal, enter:

git clone https://github.com/DamionGans/ubuntu-wsl2-systemd-script.git
cd ubuntu-wsl2-systemd-script/
bash ubuntu-wsl2-systemd-script.sh
logout

Now your Ubuntu window should close. Again, go to PowerShell and terminate Ubuntu:

wsl -terminate Ubuntu

Next, open up VcXsrv. You should be greeted with a panel that looks something like this:

Choose “One large window” and click next, and then next again. At this dialogue, in additional parameters type -ac

After pressing next, you should be done! You can save your configuration to create a shortcut that will open VcXsrv with your settings.

Click Finish and VcXsrv will open a blank window. Open ubuntu and enter:

gnome-session

In a few seconds your VcXsrv window should be populated!

Each time you start Ubuntu and your X11 server, remember to run gnome-session to enable your desktop. An alternative to this is to create a startup script that automatically runs gnome-session whenever you start Ubuntu.

Now you might notice that your desktop doesn’t look exactly like my example above. GNOME is quite customisable, and a plethora of user extensions to personalise your desktop. I won’t cover that here, but I would recommend checking out the GNOME extensions website, and searching around for some GNOME themes. One extension I do recommend installing is nautilus admin, which will allow you to right click in any folder to open a terminal there - a great convenience!

sudo apt install nautilus-admin

# An alternative if that doesn't work is

sudo apt install nautilus-extension-gnome-terminal

2.4 Using the terminal

You can copy and paste commands from the Terminal using Ctrl+Shift+C and Ctrl+Shift+V.

2.4 Building SLiM

There’s a few ways of going about building SLiM. We’ll be following the Linux/Unix installation instructions (Chapter 2.2.1) in the SLiM manual. First, install the following packages:

sudo apt-get update
sudo apt install -y build-essential cmake qt5-default qt5-qmake mesa-utils
sudo apt install -y libgl1-mesa-glx x11-apps

After this, you should have all the dependencies you need to run the installation script mentioned in the manual:

wget -o - --quiet https://raw.githubusercontent.com/MesserLab/SLiM-Extras/master/installation/DebianUbuntuInstall.sh | sudo bash -s

This will download and install SLiM, Eidos, and SLiMgui on your system. You should be able to find SLiMgui in your applications now, and you’ll have something looking like this:

2.5 Installing other useful apps

When using SLiM, you’ll need some more apps to run SLiM on remote computers and to analyse data. I recommend installing FileZilla, which will help copy files across from your computer to a remote supercomputer:

sudo apt install filezilla

For analysis, I recommend installing R, which is a tiny bit more involved.

cd /etc/apt
sudo gedit ./sources.list

# Add the following line to sources.list

deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/

Then, in terminal enter the following:

sudo apt update
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/'
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
sudo apt install r-base r-base-core r-recommended r-base-dev

This will install the latest release of R 4.0, along with some packages. Next, we can install RStudio: you can choose to install it as an app or as a server, which you can connect to via your internet browser in both Windows and Linux. With some more set up, you could also remotely connect to it via the internet, but I’ll leave that for later.

To install RStudio as an app:

sudo apt install gdebi-core

wget https://download1.rstudio.org/desktop/bionic/amd64/rstudio-1.4.1103-amd64.deb && sudo gdebi rstudio-1.4.1103-amd64.deb

Then you can run rstudio to open the app.

To install RStudio as a server app:

wget https://download2.rstudio.org/server/bionic/amd64/rstudio-server-1.4.1103-amd64.deb
sudo gdebi rstudio-server-1.4.1103-amd64.deb

Launch RStudio by running rstudio-server start, and stop the the service with rstudio-server stop. The default settings allow you to connect to the server using whichever browser you’d like with the url localhost:8787. You’ll have to login using your Linux username and password. Note that this server is running on your local machine, so to connect to your server on a different network, you’ll have to do some network configuration (namely port forwarding and setting a static IP).

When you have RStudio running (or R if you are just running from the Terminal using R like a madman), you can use install.packages("PACKAGE_NAME") to install packages. Necessary packages will be detailed in later chapters when we get to needing them. To start, try install.packages("tidyverse").

Congratulations! You now have a Linux Desktop, SLiM, RStudio, and FileZilla installed and ready to go for exploring polygenic adaptation using computer simulations!